package sample.Objects;

class depthReading implements Cloneable {
	private double depth;

	public depthReading(double e) {
		this.depth = e;
	}

	public Object clone() {
		Object o = null;
		try {
			o = super.clone();
		} catch (CloneNotSupportedException e) {
			e.printStackTrace();
		}
		return o;

	}

}

class TemperatureReading implements Cloneable {

	private long time;
	private double temp;

	public TemperatureReading(double d) {
		this.time = System.currentTimeMillis();
		this.temp = d;
	}

	public Object clone() {
		Object o = null;
		try {
			o = super.clone();
		} catch (CloneNotSupportedException e) {
			e.printStackTrace();
		}
		return o;
	}

}

class OceamReading implements Cloneable {
	private depthReading depth;
	private TemperatureReading temp;

	public OceamReading(double d, double e) {
		temp = new TemperatureReading(d);
		depth = new depthReading(e);
	}

	public Object clone() {
		OceamReading o = null;
		try {
			o = (OceamReading) super.clone();
		} catch (CloneNotSupportedException e) {
			e.printStackTrace();
		}
		o.depth = (depthReading) o.depth.clone();
		o.temp = (TemperatureReading) o.temp.clone();
		return o;
	}
}

public class DeepCopy {

	public static void main(String[] args) {
		OceamReading reading = new OceamReading(33.9, 100.5);
		OceamReading r = (OceamReading) reading.clone();
	}

}
